import numpy as np
import os
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import f1_score, precision_recall_fscore_support, classification_report
from utils.ensemble_tools import class_to_idx_map

true_labels = np.load('/home/gserver/zhangchi/tianwen/val/val-labels.npy')

all_score = np.zeros((48386, 3, 4),dtype=np.float32)
val_score1 = np.load('/home/gserver/zhangchi/tianwen/val/resnet20_crop_aug8-0.8229.npy')
val_score2 = np.load('/home/gserver/zhangchi/tianwen/val/xception-0.8138.npy')
val_score3 = np.load('/home/gserver/zhangchi/tianwen/val/xception_crop-0.7995-aug8-0.8129.npy')

all_score[:,0,:] = val_score1
all_score[:,1,:] = val_score2
all_score[:,2,:] = val_score3

x = all_score.reshape(-1, 12)

lr = LogisticRegression(multi_class='multinomial', n_jobs=4, solver='sag',)
lr.fit(x,true_labels)

pred = lr.predict(x)

val_f1 = f1_score(true_labels, pred, average='macro')
val_report = classification_report(true_labels, pred, target_names=class_to_idx_map.keys())

print pred
print val_f1
print val_report
